Vue.component('update', {
    template: `
		<el-dialog title="修改" width="900px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
              <el-row v-if="form.type == 1">
                <el-col :span="24">
                  <el-form-item label="奖励类型:">
                    <el-radio-group v-model="form.type">
                      <el-radio :label="1">见点奖</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24" >
                  <el-form-item label="最小值" prop="min">
                    <el-input typt="number" v-model="form.min" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24" >
                  <el-form-item label="最大值" prop="max">
                    <el-input typt="number" v-model="form.max" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24" >
                  <el-form-item label="条件:直推人数" prop="direct">
                    <el-input typt="number" v-model="form.direct" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
                    <small style="color: rgb(192, 196, 204);">0不限制,N:推荐N人开放</small>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24" >
                  <el-form-item label="奖励比例(%)" prop="reward">
                    <el-input typt="number" v-model="form.reward" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`,
    components:{
    },
    props: {
        show: {
            type: Boolean,
            default: false
        },
        size: {
            type: String,
            default: 'small'
        },
        info: {
            type: Object,
        },
    },
    data(){
        return {
            form: {
                min:'',
                max:'',
                reward:'',
                direct:0,
                type:1,
            },
            loading:false,
            rules: {
                min:[
                    {required: true, message: '请输入最小值', trigger: 'blur'},
                ],
                max:[
                    {required: true, message: '请输入最大值', trigger: 'blur'},
                ],
                reward:[
                    {required: true, message: '请输入奖励比例', trigger: 'blur'},
                ],
            }
        }
    },
    methods: {
        open(){
            this.form = this.info
        },
        submit(){
            this.$refs['form'].validate(valid => {
                if(valid) {
                    this.loading = true
                    axios.post(base_url + '/RangeReward/edit',this.form).then(res => {
                        if(res.data.status == 200){
                            this.$message({message: res.data.msg, type: 'success'})
                            this.$emit('refesh_list')
                            this.closeForm()
                        }else{
                            this.loading = false
                            this.$message.error(res.data.msg)
                        }
                    }).catch(()=>{
                        this.loading = false
                    })
                }
            })
        },
        closeForm(){
            this.$emit('update:show', false)
            this.loading = false
            if (this.$refs['form']!==undefined) {
                this.$refs['form'].resetFields()
            }
        },
    }
})
